﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Reg_to_head_Cmdline {
	internal class Program {
		static void Main(string[] args) {
			if (args.Length != 2) {
				Console.WriteLine("参数错误");
				return;
			}
			string[] read_file;
			try {
				read_file = System.IO.File.ReadAllLines(args[0]);
			} catch (Exception ex) {
				Console.WriteLine("无法读到文件");
				return;
			}


			List <reg> regs = new List<reg>();
			for(int i = 0; i < read_file.Length; i++) {
				var s = read_file[i];
				if (s.Length > 1) {
					regs.Add(new reg(s, i + 1)) ;
				}
			}
			foreach (var r in regs) {
				r.Parse();
				if(r.warning != "") {
					r.Report();
				}
			}
			StringBuilder sb = new StringBuilder(0x8000);
			Dictionary<string, string> symbols = new Dictionary<string, string>();

			foreach (var r in regs) {
				r.toIarDef(sb, symbols);
			}

			File.WriteAllText(args[1], sb.ToString(), new UTF8Encoding(false));


			Console.Write("按任意键退出...");

			Console.ReadKey(true);



		}
	}
}
